home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 7: Sunsite / Linux Cubed Series 7 - Sunsite Vol 1.iso / system / admin / linuxcon.000 / linuxcon / linuxconf-1.6 / apache / httpd.c < prev    next >
C/C++ Source or Header  |  1996-08-01  |  7KB  |  207 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4. #include "../misc/misc.h"
  5. #include "internal.h"
  6. #include "../paths.h"
  7.  
  8.  
  9. static HELP_FILE help_httpd ("apache","httpd");
  10. CONFIG_FILE httpd_conf (VAR_LIB_WWW_HTTPD_CONF,help_httpd
  11.         ,CONFIGF_OPTIONNAL|CONFIGF_MANAGED);
  12.  
  13. /* #Specification: httpd config / principle
  14.     Linuxconf supports the apache httpd server. While the apache server
  15.     share most of its configuration file format with ncsa httpd, I have not
  16.     made any attempt at "virtualizing" linuxconf. Linuxconf hope to really
  17.     support apache closer and closer.
  18.  
  19.     It is expect that linuxconf will grow into something more modular one
  20.     day and modules will be available to manage other things than apache
  21.     if this is needed.
  22. */
  23.  
  24. static const char HTTPD[]="HTTPD";
  25. static const char IN_USE[]="INUSE";
  26. static const char PORT[]="Port";
  27. static const char USER[]="User";
  28. static const char GROUP[]="Group";
  29. static const char SERVERTYPE[]="ServerType";
  30. static const char PIDFILE[]="PidFile";
  31. static const char STARTSERVERS[]="StartServers";
  32. static const char MAXCLIENTS[]="MaxClients";
  33. static const char MAXREQUESTSPERCHILD[]="MaxRequestsPerChild";
  34. static const char VIRTUALHOST[]="VirtualHost";
  35. static const char TIMEOUT[]="Timeout";
  36. static const char MINSPARESERVERS[]="MinSpareServers";
  37. static const char MAXSPARESERVERS[]="MaxSpareServers";
  38. static const char SCOREBOARDFILE[]="ScoreBoardFile";
  39.  
  40. static const char SERVERADMIN[]="ServerAdmin";
  41. static const char SERVERNAME[]="ServerName";
  42. static const char DOCUMENTROOT[]="DocumentRoot";
  43. static const char ERRLOG[]="ErrLog";
  44. static const char TRANSFERLOG[]="TransferLog";
  45.  
  46.  
  47. PUBLIC HTTPD_DOMAIN *HTTPD_DOMAINS::getitem(int no)
  48. {
  49.     return (HTTPD_DOMAIN*)ARRAY::getitem(no);
  50. }
  51.  
  52. static void writeif (FILE *fout,const char *title, CSSTRING &s)
  53. {
  54.     if (!s.is_empty()){
  55.         fprintf (fout,"%s\n",s.comment.get());
  56.         fprintf (fout,"%s %s\n",title,s.get());
  57.     }
  58. }
  59.  
  60. PUBLIC void HTTPD_DOMAIN::write(FILE *fout)
  61. {
  62.     fputc ('\n',fout);
  63.     writeif (fout,SERVERADMIN,serveradmin);
  64.     writeif (fout,SERVERNAME,servername);
  65.     writeif (fout,DOCUMENTROOT,documentroot);
  66.     writeif (fout,ERRLOG,errlog);
  67.     writeif (fout,TRANSFERLOG,transferlog);
  68. }
  69.  
  70. PUBLIC HTTPD_CONFIG::HTTPD_CONFIG()
  71. {
  72.     FILE *fin = httpd_conf.fopen ("r");
  73.     in_use = linuxconf_getvalnum (HTTPD,IN_USE,0);
  74.     port = 80;
  75.     startservers = 5;
  76.     maxclients = 150;
  77.     maxrequestsperchild = 30;
  78.     minspareservers = 5;
  79.     maxspareservers = 10;
  80.     servertype = 0;
  81.     pidfile.setfrom ("logs/httpd.pid");
  82.     uid.setfrom ("nobody");
  83.     gid.setfrom ("-1");
  84.     timeout = 400;
  85.     scoreboardfile.setfrom ("logs/apache_runtime_status");
  86.     if (fin != NULL){
  87.         char buf[3000];
  88.         SSTRING comments;
  89.         HTTPD_DOMAIN *dom = &defdom;
  90.         while (fgets_comments(buf,sizeof(buf)-1,fin,comments)!=NULL){
  91.             char *pt = str_skip (buf);
  92.             if (*pt == '<'){
  93.             }else{
  94.                 char word[200];
  95.                 const char *arg = str_copyword (word,pt);
  96.                 arg = str_skip(arg);
  97.                 if (strcmp(word,SERVERADMIN)==0){
  98.                     dom->serveradmin.setcomment(comments);
  99.                     dom->serveradmin.setfrom(arg);
  100.                 }else if (strcmp(word,SERVERNAME)==0){
  101.                     dom->servername.setcomment(comments);
  102.                     dom->servername.setfrom(arg);
  103.                 }else if (strcmp(word,DOCUMENTROOT)==0){
  104.                     dom->documentroot.setcomment(comments);
  105.                     dom->documentroot.setfrom(arg);
  106.                 }else if (strcmp(word,ERRLOG)==0){
  107.                     dom->errlog.setcomment(comments);
  108.                     dom->errlog.setfrom(arg);
  109.                 }else if (strcmp(word,TRANSFERLOG)==0){
  110.                     dom->transferlog.setcomment(comments);
  111.                     dom->transferlog.setfrom(arg);
  112.                 }else if (strcmp(word,PORT)==0){
  113.                     comment_port.setfrom (comments);
  114.                     port = atoi(arg);
  115.                 }else if (strcmp(word,USER)==0){
  116.                     user.setcomment(comments);
  117.                     user.setfrom (arg);
  118.                 }else if (strcmp(word,GROUP)==0){
  119.                     group.setcomment(comments);
  120.                     group.setfrom (arg);
  121.                 }else if (strcmp(word,SERVERTYPE)==0){
  122.                     comment_servertype.setfrom (comments);
  123.                     servertype = stricmp(arg,"standalone") == 0 ? 0 : 1;
  124.                 }else if (strcmp(word,PIDFILE)==0){
  125.                     pidfile.setcomment(comments);
  126.                     pidfile.setfrom (arg);
  127.                 }else if (strcmp(word,STARTSERVERS)==0){
  128.                     comment_startservers.setfrom (comments);
  129.                     startservers = atoi(arg);
  130.                 }else if (strcmp(word,MAXCLIENTS)==0){
  131.                     comment_maxclients.setfrom (comments);
  132.                     maxclients = atoi(arg);
  133.                 }else if (strcmp(word,MAXREQUESTSPERCHILD)==0){
  134.                     comment_maxrequestsperchild.setfrom (comments);
  135.                     maxrequestsperchild = atoi(arg);
  136.                 }else if (strcmp(word,TIMEOUT)==0){
  137.                     comment_timeout.setfrom (comments);
  138.                     timeout = atoi(arg);
  139.                 }else if (strcmp(word,MINSPARESERVERS)==0){
  140.                     comment_minspareservers.setfrom (comments);
  141.                     minspareservers = atoi(arg);
  142.                 }else if (strcmp(word,MAXSPARESERVERS)==0){
  143.                     comment_maxspareservers.setfrom (comments);
  144.                     maxspareservers = atoi(arg);
  145.                 }else if (strcmp(word,SCOREBOARDFILE)==0){
  146.                     scoreboardfile.setcomment (comments);
  147.                     scoreboardfile.setfrom (arg);
  148.                 }else{
  149.                     xconf_error ("Invalid line %s\n",buf);
  150.                 }
  151.             }
  152.             comments.setfrom ("");
  153.         }
  154.         fclose (fin);
  155.  
  156.     }
  157. }
  158.  
  159. PUBLIC int HTTPD_CONFIG::write ()
  160. {
  161.     int ret = -1;
  162.     FILE *fout = httpd_conf.fopen ("w");
  163.     if (fout != NULL){
  164.         fprintf (fout,"%s\n",comment_servertype.get());
  165.         fprintf (fout,"%s %s\n",SERVERTYPE,servertype ? "standalone" : "inetd");
  166.         fprintf (fout,"%s\n",comment_port.get());
  167.         fprintf (fout,"%s %d\n",PORT,port);
  168.         fprintf (fout,"%s\n",comment_startservers.get());
  169.         fprintf (fout,"%s %d\n",STARTSERVERS,startservers);
  170.         fprintf (fout,"%s\n",comment_minspareservers.get());
  171.         fprintf (fout,"%s %d\n",MINSPARESERVERS,minspareservers);
  172.         fprintf (fout,"%s\n",comment_maxspareservers.get());
  173.         fprintf (fout,"%s %d\n",MAXSPARESERVERS,maxspareservers);
  174.         fprintf (fout,"%s\n",comment_maxclients.get());
  175.         fprintf (fout,"%s %d\n",MAXCLIENTS,maxclients);
  176.         fprintf (fout,"%s\n",comment_maxrequestsperchild.get());
  177.         fprintf (fout,"%s %d\n",MAXREQUESTSPERCHILD,maxrequestsperchild);
  178.         fprintf (fout,"%s\n",pidfile.comment.get());
  179.         fprintf (fout,"%s %s\n",PIDFILE,pidfile.get());
  180.         fprintf (fout,"%s\n",comment_timeout.get());
  181.         fprintf (fout,"%s %d\n",TIMEOUT,timeout);
  182.         fprintf (fout,"%s\n",uid.comment.get());
  183.         fprintf (fout,"%s %s\n",USER,uid.get());
  184.         fprintf (fout,"%s\n",group.comment.get());
  185.         fprintf (fout,"%s %s\n",GROUP,gid.get());
  186.         fprintf (fout,"%s\n",scoreboardfile.comment.get());
  187.         fprintf (fout,"%s %s\n",SCOREBOARDFILE,scoreboardfile.get());
  188.  
  189.         defdom.write (fout);
  190.         fprintf (fout,"\n");
  191.         for (int i=0; i<domains.getnb(); i++){
  192.             HTTPD_DOMAIN *d = domains.getitem(i);
  193.             fprintf (fout,"<%s %s>\n",VIRTUALHOST,d->host.get());
  194.             domains.getitem(i)->write(fout);
  195.             fprintf (fout,"</%s>\n\n",VIRTUALHOST);
  196.         }
  197.         ret = fclose (fout);
  198.     }
  199.     linuxconf_replace (HTTPD,IN_USE,in_use);
  200.     linuxconf_save();
  201.     return ret;
  202. }
  203.  
  204.  
  205.  
  206.  
  207.